/**
 * 点击div事件
 * @param {Object} id
 */
function clickDiv(id){
	//先判断是否为IE浏览器
    if (Ext.isIE) {
        // IE浏览器需要使用dom创建，否则option创建不成功(仅IE8测试不成功，其他不确定)
        // 会降低性能
        Ext.DomHelper.useDom = true;
    }
    var divb = Ext.get("div_b_" + id);
    var div = divb.parent();
//    var elm = Ext.get("ul_" + id);
	var elm = Ext.get("dl_" + id);
	var ddNotHiddenElm = elm.select("dd{display!=none}");
	//收起展开的菜单
	Ext.select(".shrinkIcon").each(function(element){
		element.parent().parent().select("dd").each(function(dd){
			dd.set({
                "style": "display:none;"
            });
		});
//		element.set({
//        "class": "expandIcon"
//		});
		//解决IE9以下兼容问题。
		element.replaceCls("shrinkIcon","expandIcon");
	});

    // console.log(ddNotHiddenElm.getCount());
    if (ddNotHiddenElm.getCount() == 0) {
        // 都隐藏，需要显示
        var ddHiddenElm = elm.select("dd");
        var resourceID = divb.id;
//        if(resourceID.indexOf("402880885220548301522t43ae460001")!=-1){
//        	Ext.Ajax.request({
//        		url: showMsgUrl,
////      		url: 'workbench/orchid/data/msgData.jsons',
//        		params: {},
//        		success: function(response){
//        			var data = response.responseText;
//        			var jsonData = Ext.decode(data, true);
//        			var newsUserNoReadCount = jsonData.data.newsUserNoReadCount;
//        			var remindUserNoReadCount = jsonData.data.remindUserNoReadCount;
//        			for(var i=0;i<ddHiddenElm.elements.length;i++){
//        				if(ddHiddenElm.elements[i].id.indexOf("8a10e7f9557b199401557b37dfbf0001")!=-1){
//        					ddHiddenElm.elements[i].innerHTML = '<span class="title"><b class="null"></b>消息管理('+newsUserNoReadCount+')</span>'	
//        				}else if(ddHiddenElm.elements[i].id.indexOf("4028809c52207e8a015220860c5r0002")!=-1){
//        					ddHiddenElm.elements[i].innerHTML = '<span class="title"><b class="bull"></b>提醒管理('+remindUserNoReadCount+')</span>'	
//        				}
//        			}
//        		}
//        	});
//        }
        
        //		console.log(ddHiddenElm.getCount());
        ddHiddenElm.each(function(element){
            element.set({
                "style": "display:list-item;"
            });
        });
//        divb.set({
//            "class": "shrinkIcon"
//        });
        //解决IE9以下兼容问题。
        divb.replaceCls("expandIcon","shrinkIcon");
    }
    else {
        // 隐藏
        ddNotHiddenElm.each(function(element){
            element.set({
                "style": "display:none;"
            });
            /*
             element.slideOut('t', {
             easing: 'easeIn',
             duration: 200,
             remove: false,
             useDisplay: true
             });
             */
        });
        //解决IE9以下兼容问题。
        divb.replaceCls("shrinkIcon","expandIcon");
//        divb.set({
//           "class": "expandIcon"
//        });
    }
	Ext.DomHelper.useDom = false;
    // var elm = Ext.get("dd_"+id);

}

/**
 * 鼠标划入2级菜单切换菜单样式
 * @param {Object} id
 */
function overLi(id){
    var li = Ext.get("li_" + id);
    li.addCls("current");
}

/**
 * 鼠标划出2级菜单切换菜单样式
 * @param {Object} id
 */
function outLi(id){
    var li = Ext.get("li_" + id);
    li.removeCls("current");
}

/**
 * 点击2级菜单事件，打开tab页签
 * @param {Object} id
 * @param {Object} text
 * @param {Object} url
 * @param {Object} e
 */
function clickLi(id, text, url, e){
/*	if(id=="8a10e7f9557b199401557b37dfbf0001"){
		Ext.Ajax.request({
			url: showMsgUrl,
//			url: 'workbench/orchid/data/msgData.jsons',
			params: {},
			success: function(response){
				e;
				var data = response.responseText;
				var jsonData = Ext.decode(data, true);
				var newsUserNoReadCount = jsonData.data.newsUserNoReadCount;
				text = "消息管理("+newsUserNoReadCount+")";
				clickLi_(id, text, url, e);
			}
		});
	}else if(id=="4028809c52207e8a015220860c5r0002"){
		Ext.Ajax.request({
			url: showMsgUrl,
//			url: 'workbench/orchid/data/msgData.jsons',
			params: {},
			success: function(response){
				var data = response.responseText;
				var jsonData = Ext.decode(data, true);
				var remindUserNoReadCount = jsonData.data.remindUserNoReadCount;
				text = "提醒管理("+remindUserNoReadCount+")";
				clickLi_(id, text, url, e);
			}
		});
	}else{
		clickLi_(id, text, url, e);
	}*/
	clickLi_(id, text, url, e);
	function clickLi_(id, text, url, e){
		if(url == 'void'){
			Ext.Msg.confirm({
				title: '提示',
				msg: '模块创建中......'
			});
			return;
		}
		//以浏览器页签显示
		if(url.substring(0,4) == 'http'){
			var atag = Ext.get("exportResume");
			atag.set({
				"href": url
			});
			atag.dom.click();
			return;
		}

		var win = Ext.getCmp('portalWin');
		if (win != null && win != "") {
			win.close();
		}
		Ext.select("li.selectSubnav").removeCls("selectSubnav");
		var li = Ext.get("li_" + id);
		li.addCls("selectSubnav");

		var newUrl = url;
		if(newUrl.indexOf(".jsp") >= 0 || newUrl.indexOf(".html") >= 0 || newUrl.indexOf(".doc") >= 0 || newUrl.indexOf(".docx") >= 0){
			var atag = Ext.get("exportResume");
			atag.set({
				"href": newUrl
			});
			atag.dom.click();
		}else{
			var tabPanel = Ext.getCmp("viewTab");
			//var tab = tabPanel.items.get('tab-' + id);
			var tab = tabPanel.down("#tab-" + id);
			if (!tab) {
				var p = {
						title: text,
						itemId: 'tab-' + id,
						closable: true,
						closeAction: 'destroy'
				};
				tab = tabPanel.add(Ext.create(url, p));
				//菜单为“预分配参学名额”时，关闭页签给出提示信息
				var tabId = tab.id;
				var tabIdStr = tabId.substring(0,tabId.indexOf("-"));
				if(tabIdStr == 'workingCommitteePlacesFrame'){
					tab.addListener("beforeclose",function(){
						Ext.Msg.confirm({
							title: '提示',
							msg: '预分配参学名额须点击“确认报名限额”按钮后才能生效！',
							buttons: Ext.Msg.OKCANCEL,
							fn: function(id){
								if (id == 'ok') {
									tab.fireEvent('close', tab);
									tab[tab.closeAction]();
								}
								else {
									return false;
								}
							}
						});
						return false;
					});
				}
			}
			tabPanel.setActiveTab(tab);
		}
	}
}

/**
 * 修改当前用户功能
 */
function updateCurrent(id){
    Ext.create("AM.view.user.CurrentUserEdit", {
        userId: id
    });
}

/**
 * 登出按钮功能
 */
function logOut(){
    Ext.Msg.confirm({
        title: '提示',
        msg: '您确定要退出系统吗?',
        buttons: Ext.Msg.OKCANCEL,
        fn: function(id){
            if (id == 'ok') {
                window.location.href = "./logout.jsp";
            }
            else {
                return;
            }
        }
    });
}

/**
 * 点击地址窗口的省级部分事件
 * @param {Object} id
 */
function clickProvince(id){
    var elm = Ext.get("addr_city_" + id);
    if (elm.isVisible()) {
        // 隐藏方法
        elm.slideOut('t', {
            easing: 'easeIn',
            duration: 200,
            remove: false,
            useDisplay: true
        });
    }
    else {
    
        var address = Ext.get("address");
        var needHiddenDivElm = address.select("div.districtListContent{display!=none}");
        needHiddenDivElm.each(function(elment, composite, index){
            elment.slideOut('t', {
                easing: 'easeIn',
                duration: 200,
                remove: false,
                useDisplay: true
            });
        });
        
        // 展开方法
        elm.slideIn('t', {
            easing: 'easeIn',
            duration: 300,
            remove: false,
            useDisplay: true
        });
    }
}

/**
 * 城市checkbox点击事件
 * @param {Object} pid
 * @param {Object} checkbox
 */
function clickCity(pid, checkbox){
    var elmcheck = Ext.get("province_" + pid);
    if (checkbox.checked) {
        if (!elmcheck.dom.checked) {
            elmcheck.dom.checked = true;
        }
    }
    else {
        var elmdiv = Ext.get("addr_city_" + pid);
        var count = elmdiv.select("input:checked").getCount();
        if (count == 0) {
            elmcheck.dom.checked = false;
        }
    }
    
}

/**
 * 省级点击事件全选城市
 * @param {Object} id
 */
function clickAll(id, checkbox){

    var elmdiv = Ext.get("addr_city_" + id);
    var cityCheckbox = elmdiv.select("input[type=checkbox]");
    cityCheckbox.each(function(elment, composite, index){
        elment.dom.checked = checkbox.checked;
    });
}

/**
 * 打开Window窗口
 */
function openWindow(url,params){
	if(url != null && url != ""){
		Ext.create(url,params);
	}
}